package com.zhangshujie.ShoppingSystem;

import java.util.List;


public class Admin extends User {
        public Admin(String id, String username, String password, String phoneNumber, String email) {
            super(id, username, password, phoneNumber, email);
        }

        @Override
        public void changePassword(String newPassword) {
            this.password = newPassword;
            System.out.println("管理员密码修改成功！");
        }

        @Override
        public String toString() {
            return id + "," + username + "," + password + "," + phoneNumber + "," + email;
        }


        public String getPassword() {
            return password;
        }

        public void resetCustomerPassword(Customer customer, String newPassword) {
            customer.changePassword(newPassword);
            System.out.println("客户 " + customer.getUsername() + " 的密码已重置！");
        }

        public void listAllCustomers(UserManager userManager) {
            List<Customer> customers = userManager.getAllCustomers();
            for (Customer customer : customers) {
                System.out.println(customer);
            }
        }

        public void deleteCustomer(UserManager userManager, String customerId) {
            Customer customer = userManager.findCustomerById(customerId);
            if (customer != null) {
                userManager.removeCustomer(customer);
                System.out.println("客户 " + customer.getUsername() + " 已删除！");
            } else {
                System.out.println("客户ID不存在！");
            }
        }

        public void searchCustomer(UserManager userManager, String query) {
            Customer customer = userManager.findCustomerById(query);
            if (customer == null) {
                customer = userManager.findCustomerByUsername(query);
            }
            if (customer != null) {
                System.out.println(customer);
            } else {
                System.out.println("未找到客户！");
            }
        }



        public void addProduct(ProductManager productManager, Product product) {
            productManager.addProduct(product);
            System.out.println("商品 " + product.getName() + " 已添加！");
        }

        public void updateProduct(ProductManager productManager, Product product) {
            productManager.updateProduct(product);
            System.out.println("商品 " + product.getName() + " 已更新！");
        }

        public void deleteProduct(ProductManager productManager, String productId) {
            Product product = productManager.findProductById(productId);
            if (product != null) {
                productManager.deleteProduct(productId);
                System.out.println("商品 " + product.getName() + " 已删除！");
            } else {
                System.out.println("商品ID不存在！");
            }
        }

    public void searchProduct(ProductManager productManager, String query) {
        Product product = productManager.findProductById(query);
        if (product != null) {
            System.out.println(product);
        } else {
            System.out.println("未找到商品！");
        }
    }
    }
